package com.os.opencv.java.chapter9;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Sobel {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/Pictures/1700969333712.jpg");
        HighGui.imshow("wanlifuwangshi", src);
        HighGui.waitKey(0);

        Mat grad = new Mat();
        Mat gx = new Mat(), gy = new Mat();
        Mat absGx = new Mat(), absGy = new Mat();

        //提取x方向边缘
        Imgproc.Sobel(src, gx, -1, 1, 0);
        Core.convertScaleAbs(gx, absGx);

        //提取y方向边缘
        Imgproc.Sobel(src, gy, -1, 0, 1);
        Core.convertScaleAbs(gy, absGy);

        //在屏幕上显示x和y方向边缘
        HighGui.imshow("sobel - x", gx);
        HighGui.waitKey(0);

        HighGui.imshow("sobel - y", gy);
        HighGui.waitKey(0);

        //计算政府图像的边缘并在屏幕上显示
        Core.addWeighted(absGx, 0.5, absGy, 0.5, 0, grad);
        HighGui.imshow("sobel", grad);
        HighGui.waitKey(0);

        System.exit(0);

    }
}
